//
//  UserDefaultsManager.swift
//  AIGirl
//
//  Created by Rae on 2024/1/17.
//

import Foundation

class UserDefaultsManager {
    
    // 定义键
    enum Key: String {
        case girlId
        case modelId
        case currentPage
        case token
        case userName
        case grilName
        case grilAge
        case girlAvatar
        case isShowFirstAward //新手奖励
        case isInChatRoom //是否进过聊天室
        case VIPStartTime
        case VIPEndTime
        case bgPhototId
        case askPhoto //索要图片次数
        case sendMsg //发送消息次数
        case sendCoin //游客登录赠送币
        case firstMessageAlert
        // 添加其他键...
    }
    
    // 保存字符串值
    class func setString(_ value: String, forKey key: Key) {
        UserDefaults.standard.set(value, forKey: key.rawValue)
        UserDefaults.standard.synchronize()
    }
    
    // 获取字符串值
    class func getString(forKey key: Key) -> String? {
        return UserDefaults.standard.string(forKey: key.rawValue)
    }
    
    // 保存布尔值
    class func setBool(_ value: Bool, forKey key: Key) {
        UserDefaults.standard.set(value, forKey: key.rawValue)
        UserDefaults.standard.synchronize()
    }
    
    // 获取布尔值
    class func getBool(forKey key: Key) -> Bool {
        return UserDefaults.standard.bool(forKey: key.rawValue)
    }
    
    // 保存Int
    class func setInt(_ value: Int, forKey key: Key) {
        UserDefaults.standard.set(value, forKey: key.rawValue)
        UserDefaults.standard.synchronize()
    }
    
    // 获取Int
    class func getInt(forKey key: Key) -> Int {
        return UserDefaults.standard.integer(forKey: key.rawValue)
    }
    //remove
    class func removeForKey( forKey key: Key) {
        UserDefaults.standard.removeObject(forKey: key.rawValue)
        UserDefaults.standard.synchronize()
    }
    //clear
    class func clearUserDefaults() {

        let defaults = UserDefaults.standard
        
        defaults.removeObject(forKey: "girlId")
        defaults.removeObject(forKey: "modelId")
        defaults.removeObject(forKey: "currentPage")
        defaults.removeObject(forKey: "token")
        defaults.removeObject(forKey: "userName")
        defaults.removeObject(forKey: "grilName")
        defaults.removeObject(forKey: "grilAge")
        defaults.removeObject(forKey: "girlAvatar")
        defaults.removeObject(forKey: "VIPStartTime")
        defaults.removeObject(forKey: "VIPEndTime")
        defaults.removeObject(forKey: "bgPhototId")
        defaults.removeObject(forKey: "askPhoto")
        defaults.removeObject(forKey: "sendMsg")
        defaults.removeObject(forKey: "sendCoin")
        
        defaults.synchronize()
    }
}

